
<div class="eject_con">
    <div id="ms-warning"></div>
    <form id="fsadd_form" action="<?php echo url('circle/manage/friendship_add');?>?c_id=<?php echo $c_id;?>" method="post" class="base-form-style">
        <input type="hidden" value="ok" name="form_submit">
        <dl>
            <dt>圈子名称：</dt>
            <dd>
                <input type="text" name="name" class="w200 text" />
                <a href="javascript:void(0);" nctype="fsadd_search">搜索</a> </dd>
            <dd>
                <select name="cid" nctype="fsadd_select" class="w200" style="height: 100px" size='7'>
                    <option value='0'>请选择...</option>
                </select>
                <input type="hidden" name="cname" id="cname" value="" />
            </dd>
        </dl>
        <dl>
            <dt>圈子排序：</dt>
            <dd>
                <input type="text" name="sort" class="w50 text" value="255" />
            </dd>
        </dl>
        <dl>
            <dt>分类排序：</dt>
            <dd>
                <input type="radio" name="status" value="1" checked="checked" />
                显示&nbsp;
                <input type="radio" name="status" value="0" />
                隐藏 </dd>
        </dl>
        <dl class="bottom">
            <dt>&nbsp;</dt>
            <dd><a class="submit-btn" nctype="submit-btn" href="Javascript: void(0)">提交</a></dd>
        </dl>
    </form>
</div>
<script type="text/javascript">
    var c_id = <?php echo $c_id;?>;
    $(function(){
        $('a[nctype="submit-btn"]').click(function(){
            $('#fsadd_form').submit();
        });

        $('#fsadd_form').validate({
            errorLabelContainer: $('#ms-warning'),
            invalidHandler: function(form, validator) {
                $('#ms-warning').show();
            },
            submitHandler:function(form){
                ajaxpost('fsadd_form', "<?php echo url('circle/manage/friendship_add');?>?c_id="+c_id, '', 'onerror');
            },
            rules : {
                cid : {
                    min : 1
                },
                sort : {
                    required : true,
                    digits : true,
                    max : 255
                }
            },
            messages : {
                cid : {
                    min : '请选择想要添加的圈子'
                },
                sort  : {
                    required : '请填写友情圈子排序',
                    digits : '请填写数字',
                    max : '数值不能超过255'
                }
            }
        });

        $('a[nctype="fsadd_search"]').click(function(){
            var name = $('input[name="name"]').val();
            $.getJSON("<?php echo url('/circle/manage/search_circle');?>?c_id="+c_id+"&name="+name, function(data){
                if(data){
                    var select = $('select[nctype="fsadd_select"]');
                    select.html('<option value=\'0\'>请选择...</option>');
                    $.each(data, function(e, d){
                        $('<option value="'+d.circle_id+'">'+d.circle_name+'</option>').appendTo(select);
                    });
                    select.parent('dd').show();
                }
            });
        });

        $('select[nctype="fsadd_select"]').change(function(){
            var val = parseInt($(this).val());
            if(val == 0){
                $('#cname').val('');
            }else{
                var html = $(this).find('option:selected').html();
                $('#cname').val(html);
            }
        });
    });
</script>